import platform
import sys

import eel


@eel.expose
def myHello(item):
    reply = "Hello " + item
    print(reply)
    return reply


def startEel(isDevelop: bool = True):
    if isDevelop:
        webDir = ""
        # 调试状态下,vue的端口
        page = {'port': 8899}
        eel_kws = dict(
            mode='chrome',
            host='localhost',
            # eel后端端口
            port=9000,
            size=(800, 600),
        )
    else:
        # 一体项目需要指定web目录
        webDir = "web"
        page = 'index.html'
        eel_kws = dict(
            mode='chrome',
            port=0,
            size=(800, 600),
        )
    eel.init(webDir)
    # myHello("Python World!")
    # Call a JavaScript function (must be after `eel.init()`)
    # eel.myHello(
    #     "Python World!"
    # )
    try:
        eel.start(page, **eel_kws)
    except EnvironmentError:
        # If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
        if sys.platform in ["win32", "win64"] and int(platform.release()) >= 10:
            eel.start(page, mode="edge", **eel_kws)
        else:
            raise


if __name__ == '__main__':
    startEel()
